package validator;

import com.baidu.unbiz.fluentvalidator.ValidationError;
import com.baidu.unbiz.fluentvalidator.Validator;
import com.baidu.unbiz.fluentvalidator.ValidatorContext;
import com.baidu.unbiz.fluentvalidator.ValidatorHandler;
import org.apache.poi.ss.formula.ptg.PowerPtg;

import java.util.Date;

/**
 * 必须为将来的某个时间
 * Created by admin on 2017/2/18.
 */
public class FutureFluentValidator extends ValidatorHandler<Date> implements Validator<Date> {

    private String fieldName;
    private  boolean power=true;

    public FutureFluentValidator(String fieldName) {
        this.fieldName = fieldName;
    }
    public FutureFluentValidator(boolean power, String fieldName) {
        this.fieldName = fieldName;
        this.power=power;
    }

    @Override
    public boolean validate(ValidatorContext context, Date s) {

        if (s==null||power==false){
            return true;
        }

        if (s==null||new Date().getTime()<=s.getTime()) {
            context.addError(ValidationError.create(String.format("%必须为将来时间！", fieldName))
                    .setErrorCode(-1)
                    .setField(fieldName)
                    .setInvalidValue(s));
            return false;
        }
        return true;
    }
    public  static void main(String[] args){


        System.out.println(new Date().getTime()-new Date().getTime()/8400000*8400000);


    }

}

